<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>详细内容</title>
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap.min.css" type="text/css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/base/base.css" type="text/css">
    <%--<link rel="stylesheet" href="${newframe}/css/common.css" type="text/css">--%>
    <link rel="stylesheet" href="${newframe}/css/select2.min.css" type="text/css">
	<link rel="stylesheet" href="${assets}/css/views/department/addDepartment.css">
	<!--[if IE 8]>
    <meta http-equiv="X-UA-Compatible"content="IE=EmulateIE7">
	<![endif]-->
   	<%@ include file="/WEB-INF/jsp/component/commonBottom.jsp" %>
   	<script src="${assets}/bootstrapValidator/js/bootstrapValidator.js"></script>
   	<script src="${assets}/bootstrapValidator/js/language/zh_CN.js"></script>
    <script src="${newframe}/js/select2.full.zh.js"></script>
	<style>
		.clearfix input{
			text-indent:1em
		}
		.btn{
			width:100px;
			line-height:15px;
			background:#35acfd;
			color:white;
		}
	</style>
   	<script>
   	$(document).ready(function() {
        <shiro:hasPermission name="super:role">
        	initHosp("hospId");
		</shiro:hasPermission>
        var url = location.search;
        if( url.indexOf("&") != -1){
			$('.header h1').text('设备修改')
            $('#instrumentStatus').attr('disabled',true)
		}else{
            $('.header h1').text('设备新增')
			$('#instrumentStatus').attr('disabled',false)
		}

        <c:if test="${hospital!=null}">
        	$("#select2-hospId-container").text("${hospital.hospName}");
        </c:if>

        $('#myForm').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                instrumentType: {
                    validators: {
                        notEmpty: true
                    }
                },
                instrumentStatus: {
                    validators: {
                        notEmpty: true
                    }
                },
                instrumentNum: {
                    validators: {
                        numeric: true
                    }
                }
                <shiro:hasPermission name="super:role">
                ,
                hospId: {
                    validators: {
                        notEmpty: true
                    }
                }
                </shiro:hasPermission>
            }
        }).on('success.form.bv', function (e) {
            e.preventDefault();
            $.ajax({
                url:'${URL_BASE_UPDATEINSTRUMENT}',
                type:'post',
                data:$('#myForm').serialize(),
                async : false, //默认为true 异步
                error:function(){
                    alert('error');
                },
                success:function(data){
                    closeFrame();
                }
            });
        });

   	});
   	//关闭并刷新
	function closeFrame(){
		window.parent.closeModal();
	}

    function formatRepo(repo) {
        if (repo.loading) return repo.text;
        var markup = "<div class='select2-result-repository clearfix'>" +
            "<div class='select2-result-repository__title'>" + repo.hospName + "</div></div>";
        return markup;
    }

    function formatRepoSelection(repo) {
        return repo.hospName;
    }

    function initHosp(id){
        $("#"+id).select2({
            placeholder: '请选医院',
            ajax: {
                url: '${URL_HL_HOSPITAL_SELECT}',
                dataType: 'json',
                type: "post",
                delay: 250,
                data: function (params) {
                    var data=new Object();
                    data["iDisplayLength"]=10;
                    if(params.page==undefined){
                        data["iDisplayStart"]=0;
                    }else {
                        data["iDisplayStart"]= (params.page-1)*10;
                    }
                    if(params.term!=undefined){
                        data["hospName"]= params.term;
                    }
                    return data;
                },
                processResults: function (data, params) {
                    params.page = params.page || 1;
                    return {
                        results: data.data,
                        pagination: {
                            more: (params.page * 10) < data.msg
                        }
                    };
                },
                cache: true
            },
            escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
            minimumInputLength: 0,
            templateResult: formatRepo, // omitted for brevity, see the source of this page
            templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
        });
    }

    </script>
</head>
<body style="width: 98%">
<div class="header">
	<h1></h1>
</div>
<form id="myForm" class="form-horizontal" method="post" >
<input type="hidden" id="instrumentId" name="instrumentId" value="${entity.instrumentId}" />
<div class="clearfix">
	<div class="form-group mg">
		<label class="control-label">设备名称</label>
		<select id="instrumentType" name="instrumentType" class="form-control">
			<medi:configOpt name="instrumentName" key="${entity.instrumentType}"/>
		</select>
	</div>
	<div class="form-group">
		<label class="control-label">设备SN</label>
		<input type="text" id="instrumentSN" name="instrumentSN" class="form-control" value="${entity.instrumentSN}">

	</div>
	<%--<div class="form-group mg">--%>
		<%--<label class="control-label">设备型号</label>--%>
		<%--<input type="text" id="instrmentVersion" name="instrmentVersion" class="form-control" value="${entity.instrmentVersion}">--%>

	<%--</div>--%>
	<%--<div class="form-group">--%>
		<%--<label class="control-label">设备品牌</label>--%>
		<%--<input type="text" id="instrumentBrand" name="instrumentBrand" class="form-control" value="${entity.instrumentBrand}">--%>

	<%--</div>--%>

	<div class="form-group mg selectForm">
		<label class="control-label">设备状态</label>
		<select id="instrumentStatus" name="instrumentStatus" class="form-control" disabled="disabled">
			<medi:configOpt name="instrumentStatus" key="${entity.instrumentStatus}"/>
		</select>

	</div>
	<%--所属医院--%>
	<shiro:hasPermission name="super:role">
		<div class="form-group selectForm">
			<label class="control-label">所属医院</label>
			<select id="hospId" name="hospId"  class="form-control">
				<c:if test="${hospital!= null}">
					<option value="${hospital.id}">${hospital.hospName}</option>
				</c:if>
			</select>
		</div>
	</shiro:hasPermission>
	<shiro:lacksPermission name="super:role">
		<input type="hidden" id="hospId" name="hospId" class="form-control" value="${hospital.id}">
	</shiro:lacksPermission>


</div>
	<div class="form-group submitBtn">
		<button type="button" class="btn" data-dismiss="modal" id="closeModalButt" onclick="closeFrame()">关闭</button>
		<button type="submit" name="submit" class="btn">保存</button>
	</div>
</form>
<script>
	// 初始化显示数值
	$(document).ready(function(){
	    var url = decodeURI(decodeURI(location.search))
	    var name = ''
        var options = $('#instrumentType option')
		console.log(url)
	    if( url.indexOf("&") != -1 ){
            name = url.split('?')[1].split('&')[2].split('=')[1]
            for( var i = 0; i < options.length; i++ ){
                if( $(options[i]).text() == name ){
                    options[i].selected = true
                }
            }
		}else{
            for( var i = 0; i < options.length; i++ ){
                if( $(options[i]).text() == 'B21G血压计' ){
                    options[i].selected = true
                }
            }
		}
		var option = $('#instrumentStatus option')
        for( var i = 0; i < options.length; i++ ){
            if( $(option[i]).text() == '正常可租' ){
                option[i].selected = true
            }
        }

	})
</script>
</body>
</html>